MongoDB中实现类似于SQL的like查询

Mongo mongo;
		try {
			mongo = new Mongo("10.1.2.7", 27017);
			DB db=mongo.getDB("rim");
			DBCollection collection=db.getCollection("TBL_DATA_LOG");
			String personName="eb";
			Pattern pattern = Pattern.compile("^.*"  + personName+  ".*{1}quot; , Pattern.CASE_INSENSITIVE);  
			BasicDBObject basicDBObject=new BasicDBObject();
			basicDBObject.put("LOG_CODE", pattern);
			DBCursor dbCursor= collection.find(basicDBObject);
			while (dbCursor.hasNext()) {				
				BasicDBObject object=(BasicDBObject) dbCursor.next();
				System.out.println(object.getString("LOG_CODE"));
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MongoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

你可能感兴趣的:(MongoDB中实现类似于SQL的like查询)