本文介绍了loopbackjs"inq"用于对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在回送模型中具有对象字段数组.想使用"inq"选项按天过滤.已经看过文档,但是这些文档是针对字符串数组的,而不是Iam找到的.
I have array of object field in loopback model.Want to use "inq" option to filter by day.Already have seen docs but those are for array of strings,not the one Iam finding.
weekDays": [
{
"day": "Monday",
"startTime": "03:45",
"endTime": "04:23"
},
{
"day": "Wednesday",
"startTime": "03:23",
"endTime": "12:23"
}
字符串数组的语法类似于{weekDays:{inq:[]}}},帮助您在此处进行哪些修改.
Syntax for array of string is like {weekDays:{inq:[]}} ,help what modification has to be done here.
推荐答案
您可以在MongoDB
1.简单的find
方法
db.getCollection('user').find({'weekDays.day' : {$in: ["Monday"]}})
2.通过使用聚合
db.getCollection('user').aggregate([
{$unwind:'$weekDays'},
{$match : {'weekDays.day' : {$in : ['Monday']}}},
{ "$group": {
"_id": "$id",
"weekDays" : { "$push": "$weekDays" },
}},
])
3.聚集在loopback
var collection = ModelName.getDataSource().connector.collection("myCollection");
collection.aggregate(
[
{ $unwind:'$weekDays' },
{ $match : {'weekDays.day' : {$in : ['Monday']}}},
{ "$group": { "_id": "$id", "weekDays" : { "$push": "$weekDays" }}},
],
function(err, data) {
if (err) {
} else {
console.lod(data)
});
}
}
);
这篇关于loopbackjs"inq"用于对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!