0

I have many company documents like this:

{
 "name" : "testCompany",
 "code" : "150",
 "access" : [ 
    {
        "name" : "x",
        "role" : "admin"
    }, 
    {
        "name" : "y",
        "role" : "User"
    }, 
    {
        "name" : "z",
        "role" : "User"
    }
   ]
 }

I want to find a company which has the code value of '150'. And then remove the access with name of 'z'. I wrote this, but it didn't work. I don't get any errors:

collection.update(
{code: req.body.companyCode }, 
{$pull: {"access.$.name":  req.body.username}}, 
function(err, results) {
                res.send({error: err, affected: results});
                db.close();
            });

Any ideas?

1 Answer 1

1

Not familiar with node, but I think it should be:

collection.update(
{code: req.body.companyCode }, 
{$pull: {"access": {"name": req.body.username}}}, 
function(err, results) {
                res.send({error: err, affected: results});
                db.close();
            });
Sign up to request clarification or add additional context in comments.

Comments

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.