开发者

MongoDB $or query not working for me after mongorestore

I ran a mongodump and then mongorestore to move a MongoDB database from one computer to another. The data are there, I can query them (first query) and get results but using $or in a query produces no results (second query).

db.employees.find( { 'name.first' : 'Joe' })
-- vs --
db.employees.find( { $or : [ { 'name.first' : 'Joe' }]})

As far as I can tell, indexes have been recreated from system.indexes.bson, any ideas what is wrong?

indexes:

> db.employees.getIndexes()
[
    {
        "name" : "_id_",
        "ns" : "data.demployees",
        "key" : {
            "_id" : 1
        }
    }
]

I was running the query through the console, not pymongo.


To really help here, we need a few pieces of information:

  • version numbers (MongoDB and pymongo, server and new computer)
  • output from db.employees.getIndexes()
  • can you run a test on a smaller data set? (see below)
  • can you double-check data types?

Smaller Data Set

Try copying out a small set of the employees to a new collection and run the same queries:

db.employees.find().limit(100).forEach( function(x) { db.employees_test.insert(x); } )

Basically, let's try to rule out corruption of data. Then let's try to isolate the version and see if this is a known bug.

Double-check Data Types

Ensure that the data types are correct.

Is this a bug?

This could be a bug, but if it is, the bug should be trivial to reproduce. Once you've double-checked that the system is behaving incorrectly, it's time to repro this so that you can at least file a bug.


pymongo requires quotes around the special operators-- have you tried this?

db.employees.find( { '$or' : [ { 'name.first' : 'Joe' }]})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜