voxel51 / fiftyone

Refine high-quality datasets and visual AI models
https://fiftyone.ai
Apache License 2.0
8.8k stars 556 forks source link

[BUG] MultipleObjectsReturned: 2 or more items returned - database config import error #2317

Open ashley-mv opened 1 year ago

ashley-mv commented 1 year ago

System information

Commands to reproduce

import fiftyone as fo

Describe the problem

I get this error when I import fiftyone.

  File "C:\Python38\lib\site-packages\fiftyone\__init__.py", line 25, in <module>
    from fiftyone.__public__ import *
  File "C:\Python38\lib\site-packages\fiftyone\__public__.py", line 15, in <module>
    _foo.establish_db_conn(config)
  File "C:\Python38\lib\site-packages\fiftyone\core\odm\database.py", line 181, in establish_db_conn
    config = get_db_config()
  File "C:\Python38\lib\site-packages\fiftyone\core\odm\database.py", line 84, in get_db_config     
    config = DatabaseConfigDocument.objects.get()
  File "C:\Python38\lib\site-packages\mongoengine\queryset\base.py", line 281, in get
    raise queryset._document.MultipleObjectsReturned(
fiftyone.core.odm.database.MultipleObjectsReturned: 2 or more items returned, instead of 1
Skipping automatic non-persistent dataset cleanup
brimoor commented 1 year ago

Hmm strange. In order to resolve this error you will have to connect directly to your MongoDB database and delete the duplicate document that has somehow been created in the config collection of your fiftyone database.

To do this, start a mongod server in one shell:

# If you installed from pip, you should have a `mongod` binary here
MONGOD_PATH=/path/to/your/env/lib/python3.8/site-packages/fiftyone/db/bin/mongod

# If you installed from source, it should be here
MONGOD_PATH=~/.fiftyone/bin/mongod

# This is the default location where your database lives on disk
# If you customized your `database_dir` config, use that value here
DB_PATH=~/.fiftyone/var/lib/mongo

# Start mongo sever
$MONGOD_PATH --dbpath $DB_PATH

Then start an interactive shell in another terminal (if you installed from pip, I believe you'll have to install the mongo shell separately):

# If you installed FiftyOne from pip, provide your path here
MONGOS_PATH=/path/to/mongo

# If you installed from source, you should have a `mongo` binary here
MONGOS_PATH=~/.fiftyone/bin/mongo --shell

# Start mongo shell
$MONGOS_PATH --shell

Now delete the duplicate document:

# If you customized your `database_name` config, use that value here. The default is `fiftyone`
> use fiftyone

# You will see two documents here
> db.config.find({})
{ "_id" : ObjectId("XXXXX"), "version" : "0.18.0", "type" : "fiftyone" }
{ "_id" : ObjectId("YYYYY"), "version" : "0.17.2", "type" : "fiftyone" }

# Delete one of the documents
> db.config.deleteOne({"_id": ObjectId("YYYYY")})