xaxa
xaxa

Reputation: 1159

JugglingDB MongoDB Array of IDs

I'm using MongoDB adapter of Juggling-DB.

How can I run the equivalent of the following SQL query (IDs are fake)

SELECT * FROM APPS
WHERE
    active = 1
    AND (
        user_id = '12345'
        OR
        id IN ('456', '789', '012')
    )

that is "active apps that either belong to the given user or are available to all".

I tried the following:

{
    where: {
        active: true,
        or: [
            {
                user_id: '12345'
            },
            {
                _id: {
                    in: ['456', '789', '012']
                }
            }
        ]
    }
}

But it returns nothing. Looking at the source code my wild guess is that it only converts strings to MongoDB.ObjectID when _id is a single string, not an array.

Upvotes: 1

Views: 257

Answers (1)

viktortnk
viktortnk

Reputation: 2757

The mongodb query should be like:

db.apps.find({active: true, "$or": [{"user_id": "12345"}, {"_id": { $in: ['1', '2', '3']}}]})

Upvotes: 0

Related Questions