Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:14:50+00:00 2026-06-17T08:14:50+00:00

I have a schema as follows (simplified): var Permission = new Schema({ _id: String,

  • 0

I have a schema as follows (simplified):

var Permission = new Schema({
  _id: String,  // email address
  role: String  // "admin" or "member"
});

var Org = new Schema({
  name: {type: String, index: {unique: true, dropDups: true}, trim: true},
  permissions: [Permission]
});

An example document would look like this:

{
  "name": "My Org",
  "permissions" : [
    {"_id" : "joe@gmail.com", "role" : "admin"},
    {"_id" : "mary@gmail.com", "role" : "member"}
  ]
}

I am trying to delete one of the permissions rows, using the command org.permissions.remove(req.params.email), as shown in context below:

exports.removePermissions = function(req, res) {
  var name = req.params.name;
  return Org
    .findOne({name: name})
    .select()
    .exec(function(err, org) {
      if (err) return Org.handleError(res, err);
      if (!org) return Org.handleError(res, new Error("#notfound " + name));
      org.permissions.remove(req.params.email);
      org.save(function(err, org) {
        if (err) return Org.handleError(res, err);
        else return res.send(org);
      });
    });
};

When I do this, I get the following error:

TypeError: Cannot use 'in' operator to search for '_id' in joe@gmail.com
    at EmbeddedDocument.Document._buildDoc (/../node_modules/mongoose/lib/document.js:162:27)
    at EmbeddedDocument.Document (/../node_modules/mongoose/lib/document.js:67:20)
    at EmbeddedDocument (/../node_modules/mongoose/lib/types/embedded.js:27:12)
    at new EmbeddedDocument (/../node_modules/mongoose/lib/schema/documentarray.js:26:17)
    at MongooseDocumentArray._cast (/../node_modules/mongoose/lib/types/documentarray.js:62:10)
    at Object.map (native)
    at MongooseDocumentArray.MongooseArray.remove (/../node_modules/mongoose/lib/types/array.js:360:21)
    at model.Org.methods.removePermissions (/../models/org.js:159:20)

The only thing I can think of is that Mongoose does not support _id fields that are not ObjectID’s? This is strange, because I use these elsewhere in my code and it works fine (e.g. org.permissions.id(“joe@gmail.com”) works).

Any suggestions much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:14:50+00:00Added an answer on June 17, 2026 at 8:14 am

    I’m not sure why using remove there isn’t working, but you can do this atomically with findOneAndUpdate and the $pull operator:

    exports.removePermissions = function(req, res) {
      var name = req.params.name;
      return Org.findOneAndUpdate(
        {name: name}, 
        {$pull: {permissions: {_id: req.params.email}}},
        function(err, org) {
          // org contains the updated doc
          ...
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mongoose schema as follows var user_schema = new Schema({ reset :
I have a Mongoose schema (excerpt below): var PersonSchema = new Schema({ name :
I have a database schema like follows: User 1 ---- * UserRole *----1 Role
Suppose I have a user Schema as below var User = new db.Schema({ username
I have a MongoDb schema like this var User = new Schema({ UserName: {
I have an XML configuration as follows: <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:aop=http://www.springframework.org/schema/aop xmlns:tx=http://www.springframework.org/schema/tx xmlns:context=http://www.springframework.org/schema/context xsi:schemaLocation=
I have my Spring Configuration as follows: <?xml version=1.0 encoding=UTF-8?> <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:tx=http://www.springframework.org/schema/tx
I have this schema: <xs:complexType name=foo> <xs:sequence> <xs:element name=oneBar type=xs:string minOccurs=0/> <xs:element name=twoBar type=xs:string
I have a sample Solr schema as follows isPublic = boolean source = facebook|
I have a database schema as follows: FailureItem --------------- FailureID int foreign key references

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.