Reputation: 2172
I'm using Mongoid for Ruby. I have queried in my Mongo database before, but forget how it works with Mongo. I have a user model like so:
class User
include Mongoid::Document
field :email, type String
field :crypted_password, type String
...
end
How would I grab all the users or a specific user in my console? Thanks to anyone who can help
Upvotes: 0
Views: 272
Reputation: 434665
If your class is called User
then the underlying MongoDB collection will be users
. So you'd say things like:
> db.users.find() // All users
> db.users.find({ field: value }) // Users that match certain conditions
> db.users.findOne({ _id: ObjectId('...') }) // Find one user with a specific id
...
See the find
and findOne
documentation for further details.
Upvotes: 0
Reputation: 851
use *database
This returns a specific user:
db.getUser("*user")
This returns all users
db.getUsers()
Upvotes: 1