These are chat archives for Automattic/mongoose

15th
Dec 2017
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 02:48
@aadii104 You should have a .catch(console.error) or .catch(yourErrorHandler) at the end of your promise chain.
Also, you might want to share your UserModel schema if you want help debugging.
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 03:11
In express, I think .catch(next) should do the job nicely.
@panigrah As far as I know, MongoDB does not support joins during aggregation.
panigrah
@panigrah
Dec 15 2017 05:03
@joeytwiddle aggregate pipeline does support a form of join using the $lookup. I can get it to work for simple string fields if used for foreign and local keys. But not the default ObjectID
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 05:11

Ah, good to know @panigrah. It seems some people have managed it.

If it’s not working for you, my first suggestion would be: check that you are really storing ObjectIDs, and not storing a string by accident. (I use RoboMongo/3T to look at the raw data.)

My second suggestion: get a simple example working outside of mongoose, and try to work out what is different with the way your app is doing it.

आदित्य शर्मा
@aadii104
Dec 15 2017 06:36
thanks @joeytwiddle , this helped me.
Sandeep「 Flame 」
@srsandy
Dec 15 2017 07:56
Untitled.jpeg
help me out pls
i want to perform full text search on my firstName property
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 07:59
@srsandy You can search (inefficiently) using a regular expression:
fbUser.find({firstName: new RegExp(“Ann”)})
Sandeep「 Flame 」
@srsandy
Dec 15 2017 08:03
Thanks @joeytwiddle it did work
Sandeep「 Flame 」
@srsandy
Dec 15 2017 08:09
but if i search fbUser.find({firstName: new RegExp(“Ana”)}) it gives me
[] again
Adel
@AdelMahjoub
Dec 15 2017 08:12
now, where did that mongoose go, I just saw it sneaking by here ...
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 08:18
@srsandy That’s right, ‘Ana' does not match ‘Anna’.
If you want to find mis-spelled queries, you will need to look for some kind of “fuzzy text search”.
Sandeep「 Flame 」
@srsandy
Dec 15 2017 08:18
$text is not working
Paul "Joey" Clark
@joeytwiddle
Dec 15 2017 09:11

Although $text can match “blueberry” against “blueberries”, it will not match “blue” against “blueberries”.

So I don’t think MongoDB can do what you want.

https://www.google.de/search?q=mongodb+fuzzy+text+search

Mohamed Dhaker Abdeljawed
@Mdhaker
Dec 15 2017 10:49
Hello, is it possible to create an enum of subdocuments (schemas)?
is this schema correct (to use defined schemas as enum)? and how to instanciate thoose schema in order to trigger their middlewares ?
const schema = new mongoose.Schema({
    email: {
        type: String,
        required: true,
        unique: true,
        immutable: true
    },
    password: {
        type: String,
        required: true
    },
    // this is the user main basic profile
    profile : {
                    firstname: {
                        type: String,
                        required: true
                    },
                    lastname: {
                        type: String,
                        required: true
                    },
                    gender: {
                        type: String,
                        enum: ["Male", "Female"]
                    },
                    cin: {
                        type: String
                    },
                    phone: {
                        type: String
                    },
                    photo: {
                        type: String
                    },
                    nationality: {
                        type: String,
                        enum: countries
                    },
                    address: {
                        type: Address
                    },
                    birthday: {
                        type: Date
                    },
                    role : {
                      // role data embedded here
                      enum: [Admin,Trainer,BusinessAdmin,TrainingCenterAdmin]
                    }
    }

}, { versionKey: false });
stherrienaspnet
@stherrienaspnet
Dec 15 2017 20:56
Hello everyone, I just started to use mongoose with Typescript and found myself not being able to insert a simple document
I'm using promise and having a valid connection and getting succes save result but no document into mongodb