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

  • SEARCH
  • Home
  • 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 7846453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:35:07+00:00 2026-06-02T17:35:07+00:00

I’am currently playing around with MongoDB using its C# driver, trying each method in

  • 0

I’am currently playing around with MongoDB using its C# driver, trying each method in the API (which would be leagues better if they provided some examples) one by one.

And currently I’m on the Update.PullAll() method.

I’m using this POCO object for my tests:

public class Person 
{
    public ObjectId Id { get; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    public List<Skill> Skills { get; set; }
}

public class Skill 
{
    public Object Id { get; set; }
    public string Name { get; set; }
}

If populated, translates into this json object:

{
   "_id": ObjectId("4f979621682dbc1a8cefecb3"),
   "Firstname" : "John",
   "Lastname" : "Doe",
   "Skills" : [
       {
          "_id" : ObjectId("4f979621682dbc1a8cefecaf"),
          "Name" : "C#.NET"
       },
       {
          "_id" : ObjectId("4f979621682dbc1a8cefecb0"),
          "Name" : "ASP.NET"
       },
       {
          "_id" : ObjectId("4f979621682dbc1a8cefecb1"),
          "Name" : "SQL Server"
       }
   ]
}

Now, I’m trying to remove the elements from the skills collection.

Here is my code:

var server = MongoServer.Create("mongodb://localhost/?safe=true");
var db =  server.GetDatabase("test");
var collection = db.GetCollection<Person>("person");

// Retrieve the data above from  mongoDB
var _person = collection.AsQueryable()
                        .Select(p => p).Single();

// Query to reference "John Doe"
var query = Query.EQ("_id",new ObjectId(_person.Id.ToString()));

// Collection of "John Doe's" skill ids
var objIds = _person.Skills
                    .Select(p => new ObjectId(p.Id.ToString()));

// Parse the skill ids to a BsonArray
var bsonArray = BsonArray.Create(objIds);

var update = Update.PullAll("Skills" , bsonArray);

// Call the Update command
collection.Update( query, update );

Which, does nothing; it leaves my json object intact.

Can anyone help me point out where did I go wrong in my code?
Any suggestion is much appreciated, thanks.

  • 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-02T17:35:09+00:00Added an answer on June 2, 2026 at 5:35 pm

    For $pullAll to work, you have to match the whole object exactly, and cannot use just one field (even if it is called _id).

    So you’d have to include the name as well in the update command (and the fields need to be in the same order, too).

    The command you really want to use is $pull, which does what you need here, i.e. matching filtering criteria:

    In addition to matching an exact value you can also use expressions ($pull is special in this way).

    Even though it is called “pull without all”, it does pull all matched elements, not just one. The “all” just means that you have one filter (whereas pullAll has multiple elements to match).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I would like to run a str_replace or preg_replace which looks for certain words
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.