-
Notifications
You must be signed in to change notification settings - Fork 4
Querying models
Jean-Baptiste Musso edited this page Oct 28, 2013
·
1 revision
The default behavior for executing a Gremlin query is to return graph elements fetched from the database as proper Mogwai model instances.
User.gremlin("g.V("$type", "user")", function(err, elements) {
// 'elements' is an array of instantiated model of type 'user'
});
Note that passing a callback as last parameter is equivalent to chaining `.query():
User.gremlin("g.V("$type", "user")").query(function(err, elements) {
// 'elements' ...
});
If you wish to retrieve results as raw elements (ie. not instantiated as models), use .execute()
instead:
User.gremlin("g.V("$type", "user")").execute(function(err, results) {
// 'results' is an array of raw graph elements
});
Note that this also works with custom Gremlin queries defined in .groovy files bound to your Schema: you're free to pass a callback as last parameter, or chain .query()
or .execute()
.