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" : "", ... }
答案 0 :(得分:0)
所以我想到这一点,文档完全缺乏和误导,所以与JacksonCollection的findById方法形成对比,它可以将String作为Id,你不能在其他地方使用id与类型字符串,id被定义为ObjectId 所以你发送的数组必须是ObjectId
public static List<User> getUsersInfo(List<org.bson.types.ObjectId> ids) {
.
.
.
}