在MongoDB中检索数据

时间:2017-06-09 05:37:53

标签: mongodb

{
    "ID" : 7,
    "vendor" : "Gold's Gym",
    "savings" : 50,
    "value" : 300,
    "description" : "Get a 3 month membership for $250 ($300 value)",
    "terms" : "Non transferrable",
    "product" : "Membership",
    "expires" : {
            "year" : 2017,
            "month" : 7,
            "date" : 31
    },
    "code" : "GYM-1",
    "tags" : [
            "fitness"
    ]
},
{
    "ID" : 8,
    "vendor" : "Golds Gym",
    "discount" : 15,
    "description" : "Get 15% discount on fitness classes",
    "terms" : "Non transferrable",
    "exceptions" : "Not applicable to swimming classes",
    "product" : "Classes",
    "purchaseValidity" : {
            "year" : 2017,
            "month" : 7,
            "date" : 31
    },
    "expires": {
            "year" : 2017,
            "month" : 12,
            "date" : 31
    },
    "code" : "GYM-2",
    "tags" : [
            "fitness"
    ]
}

这是较大代码的一部分。但是,我想检索带有标签的数据项:提供折扣的健身:$ gte 10或节省10以上

这是我开始使用的内容,但是我无法找到适用于折扣和健身的语法

items.find({tags: "fitness"}, {discount: {$gte: 10}}).pretty()

1 个答案:

答案 0 :(得分:0)

你可以这样做: -

1. $elemMatch用于数组匹配。

2. $和默认情况下在查询中。

 SELECT TOP 1000 * 
 FROM Users u
    LEFT JOIN Feeds f ON f.id = u.feed_id
    LEFT JOIN FeedTracks ft ON ft.feed_id = f.id
 where not exists 
(select 1 
from FeedTracks  ft1 
where ft1.feed_id = f.id 
  and ft1.track_id = <<track_id>>)

感谢。