0
我試圖按照這個post在Java中創建「包含」查詢。問題是它給我一個錯誤。使用Java和MongoDB創建'包含'查詢
此刻,我有以下代碼:
MongoClient mongoClient = null;
DBCursor cursor = null;
mongoClient = new MongoClient("localhost" , 27017);
DB db = mongoClient.getDB("bd-films");
DBCollection coll = db.getCollection("films");
DBObject query = new BasicDBObject({"title" : {$regex : "name"}});
cursor = coll.find(query);
它給我的錯誤是在「查詢」行:
Syntax error on token ""title"", invalid Label
Syntax error, insert ";" to complete Statement
Syntax error on token ")", delete this token
我用光標將其插入一個JTable 。
驅動程序:mongo-java-driver-3.4.2
在此先感謝。
也許您的查詢應該是這樣的...... 'DBOBJECT查詢=新BasicDBObject( 「稱號」,新BasicDBObject( 「$正則表達式」,「名稱「));' –
解決了我的問題,謝謝 –