Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can shell commands use in mongoose directly? #4894

Closed
RifeWang opened this issue Jan 12, 2017 · 2 comments
Closed

can shell commands use in mongoose directly? #4894

RifeWang opened this issue Jan 12, 2017 · 2 comments
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@RifeWang
Copy link

If i have some data defined in mongoDB , i can get documents in shell through db.mycollection.find(), my question is can i write the same command db.mycollection.find() as a param through a function and then get the result , and do i have to use schema or model?

@sobafuchs
Copy link
Contributor

sobafuchs commented Jan 12, 2017

Sorry, I'm a bit confused about what you're asking. I think you're asking can you pass in mongo shell parameters to mongoose queries. If so, the answer is yes. Here's an example:

mongodb shell command

db.users.update({ _id: someRandomId }, { $addToSet: { 'data.cars': 'Audi' })

mongoose function

User.update({ _id: someRandomId }, { $addToSet: { 'data.cars': ' } })
    .then(...)
    .catch(...);

You have to use a model (not a schema, models are created from schemas).

@sobafuchs sobafuchs added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Jan 12, 2017
@RifeWang
Copy link
Author

@varunjayaraman I mean that i like mongojs's API that emulates the official mongodb API as much as possible , model and schema doesn't exit in official mongodb API , but i have to operate mongodb through model in mongoose, but i think i have a little understand about that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants