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 8556691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:24:37+00:00 2026-06-11T15:24:37+00:00

I have read the MongoDB documents however nowhere can I find an example that

  • 0

I have read the MongoDB documents however nowhere can I find an example that outlines what I am trying to do.

The closes I come is:

    > t.insert({x: [1,2,3,4,3,2,3,4]})
    > t.find()
    { "_id" : ObjectId("4bde2ad3755d00000000710e"), "x" : [ 1, 2, 3, 4, 3, 2, 3, 4 ] }
    > t.update({x:3}, {$unset:{"x.$":1}})
    > t.find()
    { "_id" : ObjectId("4bde2ad3755d00000000710e"), "x" : [ 1, 2, null, 4, 3, 2, 3, 4 ] }

However, this won’t work with what I want to do, as my collection looks like

array (
  'offers' => 
  array (
    0 => 
    array (
      'validto' => 'Thurs',
      'validfrom' => 'Mon',
      'percentage' => '0.05',
      'cashback' => '2',
      'minspend' => '40',
      'status' => 'pending',
      '_id' => '1347940686722',
    ),
    1 => 
    array (
      'validto' => 'Thurs',
      'validfrom' => 'Mon',
      'percentage' => '0.06',
      'cashback' => '3',
      'minspend' => '50',
      'status' => 'pending',
      '_id' => '1347940705277',
    ),
    2 => 
    array (
      'validto' => 'Sun',
      'validfrom' => 'Fri',
      'percentage' => '0.04',
      'cashback' => '2',
      'minspend' => '50',
      'status' => 'pending',
      '_id' => '1347940730663',
    ),
    3 => 
    array (
      'validto' => 'Sun',
      'validfrom' => 'Fri',
      'percentage' => '0.05',
      'cashback' => '3',
      'minspend' => '60',
      'status' => 'pending',
      '_id' => '1347940743513',
    ),
    4 => 
    array (
      'validto' => 'Sun',
      'validfrom' => 'Fri',
      'percentage' => '0.05',
      'cashback' => '5',
      'minspend' => '100',
      'status' => 'pending',
      '_id' => '1347940755230',
    ),
  ),
  'store_id' => new MongoId("5046cd963cd202c49d3140e7"),
)

Now if I want to remove the 3 array (but key here is I won’t KNOW if it’s 0-4 array; all I have is the data inside that sub array and the _id of the collection row).

Here is what I was thinking. However I got stuck.

$collection->update(array("store_id"=>$this->data['_id'], array("offers._id"=>1347940686722)), array('$unset'=>array("offers.$"=>1)));
  • 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-11T15:24:39+00:00Added an answer on June 11, 2026 at 3:24 pm

    Here is how I solved it

    $collection->update(array("store_id"=>new MongoId("5046cd963cd202c49d3140e7")), array('$pull'=>array("offers" =>array("id"=>"1347940755230"),false,false)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read the image file stored in a MongoDB, to do that
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read that mongoDB don't write data to disk right away, it does
first time i'm using MongoDB. I have read this example: SELECT a,b FROM users
I read that MongoDB documents are limited to 4 MB in size. I also
I have read various posts in stackoverflow and I am trying to figure out
I have read that GLSL (specifically v1.0.17: my application is running under WebGL) compilers
I have read numerous people with this question and have tried numerous strategies. However,
I understand that I must have public read and write properties on my class
I have an application that is based on mongodb + spring and a RESTful

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.