These are chat archives for Automattic/mongoose

14th
Jun 2016
Mohamed Nasrullah
@nasr18
Jun 14 2016 05:37
i have developed a chat room and need to show chat history based on time
but its printing in wrong order.
what to do
i need to do fetch last 10 history and sort it according to time. i am getting last 10 record, but sorting is wrong.
LeonineKing1199
@LeonineKing1199
Jun 14 2016 15:42

Well, if you need to sort, you should go about sorting.

By which I mean, you can sort at the application level. You can have your JS do the sorting for you.

Vaginaminer
@Vaginaminer
Jun 14 2016 19:05
how do i make google change colour
Vlado Tesanovic
@vladotesanovic
Jun 14 2016 21:09
Even if specify custom Promise
import { Mongoose } from "mongoose";

const connection: Mongoose = new Mongoose();

connection.Promise = global.Promise;

// export instance of database
export let mongo: Mongoose = connection.connect(...);
message Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html is still there
LeonineKing1199
@LeonineKing1199
Jun 14 2016 21:23

You shouldn't have to export an instance of the database. Or at least, we don't.

We have a base-level file from which all of our server routes derive from and we just put mongoose.Promise = global.Promise and it all works fine.

Vlado Tesanovic
@vladotesanovic
Jun 14 2016 21:28
@LeonineKing1199 i am not sure i understand you, you still have one file for db, and you export mongo from that file for all models?
LeonineKing1199
@LeonineKing1199
Jun 14 2016 21:29
Because of how JS and require works, mongoose is basically just a giant global mutable object.
We mutate once and it seems to propagate everywhere
So like, we'll just require('mongoose') somewhere else and the Promise switch will have happened but only because that file is required after the mutation
Vlado Tesanovic
@vladotesanovic
Jun 14 2016 21:32
@LeonineKing1199 I do that also
But forget, i am ready for sleep ( i am using mockgoose and i put this line in main connection file )
it works as it should
LeonineKing1199
@LeonineKing1199
Jun 14 2016 21:33
Hey, that's good news! Normally, I'm not all that helpful :laughing:
Vlado Tesanovic
@vladotesanovic
Jun 14 2016 21:35
:) you are doing fine here, you always try to help people
I am having one problem, it is bigger than previous one, but it is related more to mockgoose with mongoose
If i use 'populate' on one model, and i didn't create population model i got error : Uncaught MissingSchemaError: Schema hasn't been registered for model "Company". Use mongoose.model(name, schema)
Vlado Tesanovic
@vladotesanovic
Jun 14 2016 21:49
From some very weir reason, mockgoose require Capitalized name: const companyModel: ICompanyDocumentModel = <ICompanyDocumentModel>mongoose.model<ICompanyDocument>("Company", companySchema);
for model