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?

asked Jul 9, 2014 at 23:14

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();
 });
answered Jul 10, 2014 at 0:32
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.