Mongo update to 3.2 gives error 'GridFS: Index with name: files_id_1_n_1 already exists with different options' - mongodb

After updating mongo from 3.0 to 3.2, I get the following error when trying to put a new file in my gridFS with mongofiles:
2016-10-25T15:23:10.765+0200 Failed: error while storing 'execute.sh' intoGridFS: Index with name: files_id_1_n_1 already exists with different options
As a result the files are partially inserted in the GridFS. I can see the entries in the collections .chunks and .files but I cannot get the stored files with mongofiles or Java driver.

The solution was to drop the .file collection index files_id_1_n_1.
I did it with robomongo but you can do it also directly with mongo console
db.getCollection('configs.chunks').dropIndex('files_id_1_n_1')
Then I just put a new file with mongofiles and it has recreated the index.
I have re-indexed by security but maybe it was not necessary.
db.getCollection('configs.chunks').reIndex()
I did not see any difference between the two indexes and maybe my solution is not the best one but it worked.

Related

How can I query an FS collection in Meteor from the command line?

It is very useful to run meteor mongo and query collections from the command line, for debugging purposes, etc.
Recently, I have added the collectionFS package to enable image storage in the database. However, I am unable to query the database from the command line.
db.fs.collection_name.find() is not doing the trick, and I can't seem to find the correct command anywhere.
Go to the Meteor Mongo console: meteor mongo
See all the collections that are available: show collections
Look for the one that has cfs.collection_name.files
Choose the one that has your collection name. For example, I'm using collectionFS with gridFS for images. When I type show collections, I see cfs_gridfs.images.files so I just do: db.cfs_gridfs.images.files.find() to see those files.
Hope that helps.
If you find it difficult to use the command line or terminal, you have a UI for MongoDB called Robomongo which is easy to install and use. I use Meteor with its default port number and then in Robomongo it is used as 3001.
And the query to view collection here is same as db.collection_name.find().

MongoDB "j must be numeric or a boolean value"

I've set up my own local mongodb (v. 3.0.2) instance on a local ubuntu version (14.10) and I'm using genghis(v. 2.3.11) to visualize it. My programm is able to create new documents in the database, but when I try to save a newly created document or delete a document in genghis it always returns "j must be numeric or a boolean value" but it still creates/deletes the document. The error doesn't show up when I edit a document. The only thing I could find when I tried to find a solution on google was this: https://github.com/mongodb/mongo/blob/master/src/mongo/db/write_concern_options.cpp which makes me think that it's a problem with my mongodb setup (and has nothing to do with genghis), but I do not know how to resolve this.
Have you tried running the code against Mongo 2?
I ran into this same error when I tried connecting to Mongo 3 from a service that was using client libraries intended for Mongo 2.

Where can I find MongoDB documents created inside Meteor?

New to Meteor and MongoDB here. I have mongoDB running as a service in my server, and from what I understand, Meteor installs it's own mongoDB in the .meteor directory by default, unless you specify otherwise. I know native MongoDB stores its data in data/db folder, but where are the documents located for MongoDB as part of Meteor?
I have found that the mongoDB binary is found (for me) at
~/.meteor/packages/meteor-tool/.1.0.35.ftql1v++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/mongodb/bin/mongod
But scooping around that area didn't lead me to any documents, nor could I find any mongodb.conf, collection.0, collection.ns files. And there's no directory like .meteor/local/db as some answers suggested.
My question is similar to this one, however, I'm looking for the location on disk of the database documents, rather than the location of the address to access the database.
Question
Where are the documents located for MongoDB as part of Meteor?
They are saved in your project directory at .meteor/local/db.

Creating Indexed MongoDB during installation

I am creating an installation for a system using .NET and MongoDB. I wrote a batch to ensure indexes on DB but it would not work unless you have collection created. Is it a bad practice to do smth like:
db.Customers.save({username:"mkyong"})
db.Customers.remove({})
db.Customers.ensureIndex({SystemId:1,CampaignId:1,LocalIdentifier:1})
Use the createCollection command:
db.createCollection("Customers")
db.Customers.ensureIndex({SystemId:1,CampaignId:1,LocalIdentifier:1})

Where does MongoDB store its documents?

I have inserted and fetched data using MongoDB, in PHP. Is there an actual copy of this data in a document somewhere?
By default Mongo stores its data in the directory /data/db.
You can specify a different directory using the --dbpath option.
If you’re running Mongo on Windows then the directory will be C:\data\db, where C is the drive letter of the working directory in which Mongo was started. This is quite confusing, so on Windows I’d recommend that you always specify a data directory using --dbpath.
MongoDB stores it's data in the data directory specified by --dbpath. It uses a database format so it's not actual documents, but there are multiple documents in each file and you cannot easily extract the data from this format yourself.
To read and/or update a document you need to use a MongoDB client, in the same way that you send SQL queries to MySQL through a MySQL client. You probably want to do it programmatically by using one of the client libraries for your programming language, but there is also a command-line client if you need to do manual updates.