Take the 2-minute tour ×

I'm using MongoDB on Rails. If I want to add a new key-value pair in the existing collection, what is the syntax to do it? Suppose the collection name is User, is it similar to

User.create(:name => "john")


share|improve this question

1 Answer 1

up vote 1 down vote accepted

Are you using Mongo_mapper or Mongoid (then you must have an User model)?

User.create(:name => "John")

With ruby driver, is something like this:

collection = db["User"]
collection.insert(:name => "John")

But first, you need to make a connection, and choose database


share|improve this answer

Your Answer


