再一次,我花了很多令人沮丧的时间试图找出对 mongodb 和 jackson 客户端来说听起来很简陋但不成功的东西。叹息!所以我有一个用户 ID 列表,我试图找到与这些 ID 匹配的用户,但似乎我无法让它工作,我尝试了以下所有查询,但没有一个返回任何数据。非常感谢任何帮助:
public static List<User> getUsersInfo(List<String> ids) {
Logger.debug("ids" + ids);
DBCursor<User> cursor = coll.find().in("_id",ids);
System.out.println(cursor.size());
cursor = coll.find().in("id",ids);
System.out.println(cursor.size());
cursor = coll.find(DBQuery.in("id", ids));
System.out.println(cursor.size());
cursor = coll.find(DBQuery.in("_id", ids));
System.out.println(cursor.size());
输出:
[debug] application - ids[51eb40b73004b5cf0960505a, 51eb41de3004b2496a916177, 51eb42023004b2496a916178]
0
0
0
0
mongodb数据:
db.users.find()
{ "_id" : ObjectId("51eb40763004b5cf09605055"), "email" : " ", ...}
{ "_id" : ObjectId("51eb40b73004b5cf0960505a"), "email" : " ",...}
{ "_id" : ObjectId("51eb41de3004b2496a916177"), "email" :"",...}
{ "_id" : ObjectId("51eb42023004b2496a916178"), "email" : "", ... }