title: How can I fake a multi-item $pop in MongoDB?
body: <p>Quick question from someone new to Mongo.</p>
  
  <p>I have a collection of documents that (simplified) look like this:</p>
  
  <pre><code>{"_id":&lt;objectID&gt;, "name":"fakeName", "seeds":[1231,2341,0842,1341,3451, ...]}
  </code></pre>
  
  <p>What I really need is a $pop that pops 2 or 3 items off my list of seeds, but $pop currently only works for <a href="http://docs.mongodb.org/manual/reference/operator/update/pop/" rel="nofollow">one</a> item, so I'm trying to look for another way to accomplish the same thing.</p>
  
  <p>The first thing I looked at was doing $push/$each/$slice with an empty "each", like:</p>
  
  <pre><code>update: { $push: { order: { $each: [ ], $slice: ?}}}
  </code></pre>
  
  <p>The problem here is that I don't know exactly how long I want my new slice to be (I want it to be "current size - number of seeds I popped"). If the $slice modifier worked like the $slice projection, this would be easy, I could just do $slice: [ #of seeds, ], but it doesn't so that doesn't work.</p>
  
  <p>The next thing I looked at was getting the side of the array and using that as an input to $slice, like:</p>
  
  <pre><code>update: { $push: { seeds: { $each: [ ], $slice: {$subtract: [{$size:"$seeds"}, &lt;number of seeds to pop&gt;]}}}}
  </code></pre>
  
  <p>But Mongo tells me "value for $slice must be numeric value and not an Object", so apparently the result of $subtract is an Object not a number.</p>
  
  <p>Then I tried to see if I could "remove" items from the array based on an empty query with a $limit, but apparently limit gets applied later in the pipeline, so I couldn't manage to make that work.</p>
  
  <p>Any other suggestions, or am I out of luck and need to go back to the drawing board?</p>
  
  <p>Thanks so much for help/input.</p>