I'd like to retrieve all documents from a MongoDB collection, where users
field is either numeric or a string, consisting of all digits (1, 2, 19, or "4", "19", ...)
I query:
db.getCollection('collection').find(
{
users: { $or : [ { $type: [1, 16, 18, 19] },
{ $regex: /^[0-9]+$/ } ]
}
}
)
... and get the error "Unknown operator $or".
This works:
db.getCollection('collection').find(
{
$or: [
{users: { $type: [1, 16, 18, 19] } },
{users: { $regex: /^[0-9]+$/ }}
]
}
)
Why doesn't the first variant work?