0

I have this schema (groupschema)

const mongoose = require('mongoose')

const GroupSchema = new mongoose.Schema({
CreatedBy:String,
Name:String,
Link:String,
Password:String,
Periods:Number,
Members:Array,

})

module.exports = mongoose.model('groups', GroupSchema, 'groups')

And Members is an array of objects. This is how members is stored.

   Members[ {
    Email:req.user.email,
    DisplayName:displayname,
    GoogleId:req.user.googleId,
    Image:req.user.image,
    }]

I want to find the each user's object with their googleId. How do I find their objects with just their googled looking through every single group document?

I've tried this, but it keeps returning an empty array.

 const datafound = await groupschema.find({ "Members": { googleId: req.user.googleId } });

Thank you

1 Answer 1

1

I think you're typo, it should be GoogleId

const datafound = await groupschema.find({ "Members": { GoogleId: req.user.googleId } });
Sign up to request clarification or add additional context in comments.

1 Comment

Yup you are correct - Realized that a bit ago, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.