These are chat archives for Automattic/mongoose

15th
Jun 2016
James Lee
@uptownhr
Jun 15 2016 06:04
@vkarpov15 I'm pondering on the idea of writing a mongoose universal wrapper/plugin. Seems like we can easily use the pre hooks to toggle between client/server. However, I'm not sure where to hook into to change the way the commands are executed. Any recommendations on a place to start? Maybe you even know of a project that is attempting this. I know of minimongo, but that is not mongoose :).
if server, nothing changes
if client, send command through websockets
maybe i need to change the driver?
is there an interface to switch out the driver?
Pier-Luc Gagnon
@Nepoxx
Jun 15 2016 20:33
You can't use multiples .where() to perform a query? (Model.where('foo').equals('bar').where('foo2').equals('bar2'))
LeonineKing1199
@LeonineKing1199
Jun 15 2016 20:35
You should be able to...
// chaining
User
.where('age').gte(21).lte(65)
.where('name', /^vonderful/i)
.where('friends').slice(10)
.exec(callback)
That's from the docs.
If that doesn't work in the wild then maybe their docs are just wrong or are out of date
Pier-Luc Gagnon
@Nepoxx
Jun 15 2016 20:39
This message was deleted
I'm only trying to increment a number using a dynamic query XD
Pier-Luc Gagnon
@Nepoxx
Jun 15 2016 20:50
AFAIK it's because I can't do Model.findOne().where().update({$inc: {foo: 1}}, {new: true}).exec() since update() with 2 parameters expect criteria and doc
Pier-Luc Gagnon
@Nepoxx
Jun 15 2016 20:56

It seems counter-intuitive that you can combine both the fluent api and the regular one. Like if I do the following:

User
.where('age').gte(21).lte(65)
.update({age: {$gte: 66}}, {$inc: {age: -1}})
.exec()

What do you expect the query to look like?

LeonineKing1199
@LeonineKing1199
Jun 15 2016 20:57
Maybe Mongo is rejecting the SQL-ness of using where :laughing:
Pier-Luc Gagnon
@Nepoxx
Jun 15 2016 20:57
haha :P