Robomongo: Code Completion based on model

Created on 7 Oct 2016  路  5Comments  路  Source: Studio3T/robomongo

I would love it if Robomongo completed not only commands but also the model so that when I type something like:

user. a popup would show up with

lastName
email
etc...

for a document like this:

{
  _id: ...
  user: {
    firstName: 'Bill',
    lastName: 'Smith',
    email: '[email protected]'
  },
  manager: {...}
  moreProperties: {...}
}

I understand that documents don't have to be consistent, but even partially working completion would be better than none.

Also, question:

Why did Robomongo decide to follow the pattern:

db.getCollection('users').find({})
rather than
db.users.find({})

Is there some performance difference that I'm unaware of? At face value they both appear to do the exact same thing, and the second one is less code.

enhancement

Most helpful comment

@zeg-io Aside from reserved/conflicting collection names (which vary by version of MongoDB), there are also collection names that are valid for storage but not JavaScript identifiers. For example, collection names starting with anything other than a letter or underscore (eg. a number or unicode character) must also use getCollection().

The list of possible exceptions is harder (and more fragile) to deal with than using the more verbose syntax for generated queries: https://github.com/paralect/robomongo/commit/bb988da66aad257f5b050c1e2fa38028f2529df7.

You are always free to use shorter names when writing your scripts (as long as you know there aren't any conflicts).

All 5 comments

Hi @zeg-io, thanks a lot for your suggestion! We will consider this enhancement during team meeting.
Regarding db.getCollection() method you can read here https://docs.mongodb.com/v3.2/reference/method/db.getCollection. In short we do so because of possible conflict between database method and collection name. You will find a good example in MongoDb docs with db.auth() method.
Please let me know in case of any questions.

Thank you for the explanation on the getCollection() method. It _does_ make sense when supporting all projects, but it's unfortunate that the few projects which might use reserved words override simplicity.

Perhaps a solution would be to default to db.collection but also keep a reserved word list so that folks who use it (or are about to) can be warned and the explanation provided to them? IDK. I just hate having to make something more complicated because of a few who might need it.

@zeg-io Aside from reserved/conflicting collection names (which vary by version of MongoDB), there are also collection names that are valid for storage but not JavaScript identifiers. For example, collection names starting with anything other than a letter or underscore (eg. a number or unicode character) must also use getCollection().

The list of possible exceptions is harder (and more fragile) to deal with than using the more verbose syntax for generated queries: https://github.com/paralect/robomongo/commit/bb988da66aad257f5b050c1e2fa38028f2529df7.

You are always free to use shorter names when writing your scripts (as long as you know there aren't any conflicts).

Thank you, this is actually great information!

What would you think of an option in settings to allow the default to be one way or another? (I've used the short version manually, which is what prompted the entire question).

Either way, thanks for the great and thoughtful responses!

Any progress on main subject: Code Completion based on model? This is definitely an incredible feature that would greatly improve Robo 3T.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stennie picture stennie  路  4Comments

juliashibalko picture juliashibalko  路  3Comments

imkratos picture imkratos  路  4Comments

kphamilton picture kphamilton  路  3Comments

murshid1988 picture murshid1988  路  3Comments