Gowtham Saminathan
Gowtham Saminathan

Reputation: 45

Get data with not,and

MongoDB get data with not,and How to get value for INID not equal to 1 and SESSION not equal to 1 ( need to match INID and SESSION in same document ).

Ex:

{
    "_id" : ObjectId("5946800b962d74070729407a"),
    "INID" : 2,
    "SESSION" : 1,
    "TD" : ISODate("2017-06-18T13:28:43.409Z"),
    "ID" : 2,
    "OUT" : [ 
        {
            "score" : 50,
            "id" : "0",
            "out" : {
                "status" : "unreachable"
            }
        }
    ]
}

{
    "_id" : ObjectId("5946800b962d74070729407a"),
    "INID" : 3,
    "SESSION" : 1,
    "TD" : ISODate("2017-06-18T13:28:43.409Z"),
    "ID" : 2,
    "OUT" : [ 
        {
            "score" : 50,
            "id" : "0",
            "out" : {
                "status" : "unreachable"
            }
        }
    ]
}

{
    "_id" : ObjectId("5946800b962d74070729407a"),
    "INID" : 1,
    "SESSION" : 1,
    "TD" : ISODate("2017-06-18T13:28:43.409Z"),
    "ID" : 2,
    "OUT" : [ 
        {
            "score" : 50,
            "id" : "0",
            "out" : {
                "status" : "unreachable"
            }
        }
    ]
}

I want the first two documents.

Upvotes: 0

Views: 61

Answers (1)

Alex P.
Alex P.

Reputation: 3171

Well, this worked for me:

db.yourCollectionName.find(
    { $or : [ { INID : {$gt: 1} }, { SESSION : {$gt: 1} } ] }
)

With this query you can have INID larger than 1 or SESSION larger than 1 or both larger than one. Why would you need to negate?

I guess you can also do this:

db.yourCollectionName.find(
    { $or : [ { INID : {$ne: 1} }, { SESSION : {$ne: 1} } ] }
)

Upvotes: 1

Related Questions