Javascript 如何使用moongoose查找mongodb中的所有文档
这是我的查询,以获取医生收藏 这是我的id数组Javascript 如何使用moongoose查找mongodb中的所有文档,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,这是我的查询,以获取医生收藏 这是我的id数组 var getData=['123431243124','13412342314321'] dbModel.user.find({ 'tags' : {$all:getData } }, function(err, data) { if (!err) { if (data == null) { res.status(202).json({
var getData=['123431243124','13412342314321']
dbModel.user.find({
'tags' : {$all:getData }
}, function(err, data) {
if (!err) {
if (data == null) {
res.status(202).json({
"success": "0",
"message": "User not found"
});
} else {
console.log(data)
}
} else {
res.status(200).json({
"success": "0",
"message": err
});
}
});
我在控制台中得到空数组
我所犯的错误是什么?我如何才能做到这一点?尝试使用
$in
而不是$all
例如
尝试使用
$in
而不是$all
例如
你能分享模型吗?你能分享模型吗?我们应该做回调吗,因为我需要在函数中返回它吗?我们应该做回调吗,因为我需要在函数中返回它
Model.find({'tags' : {$in:getData }}, function(err, data) {
if(err){
res.status(200).json({
"success": "0",
"message": err
});
}else{
if (data == null) {
res.status(202).json({
"success": "0",
"message": "User not found"
});
} else {
console.log(data)
}
}
});
You must first create the DoctorSchema of your document after that create the model and from your model you can do your query
var doctorSchema = new mongoose.Schema({})
var Doctor = mongoose.model("doctor",doctorSchema)
var getData = ['123431243124', '13412342314321']
Doctor.find({tags: {$all: getData }},function(err,datas){
if(err){
console.log(err)
} else {
// use your data here
}
})