【发布时间】:2018-06-28 07:50:10
【问题描述】:
我是 mongodb 的新手,我有一个这样的测试集合:
{ "_id" : ObjectId("5afce40ae1def619f8c591f1"), "location" : "shanghai", "version" : "1.14", "platform" : 1 }
{ "_id" : ObjectId("5afce43ce1def619f8c591f3"), "location" : "beijing", "version" : "1.2", "platform" : 1 }
它在 shell 中运行良好:
db.test.aggregate([{$match: { 'location':{ $in:['beijing','shanghai'] } , 'platform':{ $in:[1]} }}])
它确实可以像这样在 java MongoClient 中工作:
List<Bson> filter = Arrays.asList(
Document.parse("{$match: { 'location':{ $in:['beijing','shanghai'] } }}")
);
AggregateIterable<Document> doc = mongoClient.getDatabase(db).getCollection(collectionName).aggregate(filter);
当 $in 使用 int 数组时,它不起作用并返回一个空数组:
List<Bson> filter = Arrays.asList(
Document.parse("{$match: { 'location':{ $in:['beijing','shanghai'] } , 'platform':{ $in:[1]} }}")
);
AggregateIterable<Document> doc = mongoClient.getDatabase(db).getCollection(collectionName).aggregate(filter);
【问题讨论】:
-
帮助 ~-~ ~-~ ~-~
-
它的工作......
标签: mongodb mongodb-query mongodb-java