title: Limit Mongo.db access to a structure to 1 user at a time
body: <p>I have a Gallery collection which has an <code>images</code> array</p>
  
  <pre><code>[
  {
    _id: "549e2a2bdb9021b51d96ac84",
    images: [
    {
      path: "abc123.png",
      recycles: 0
    }
    ]
  },
  {
    _id: "549e2a2bdb9021b51d96ac85",
    images: [
  {
    path: "abc123.png",
    recycles: 0
  }
  ]
  }
  ]
  </code></pre>
  
  <p>Alice requests a Gallery with only 1 image.
  Alice will upload a second image to this Gallery.
  Bob requests a Gallery with only 1 image. How do I mark the first Gallery so that Bob doesn't get the same image from Alice?</p>
  
  <p>I'm considering marking the first Gallery with an accessed timestamp when Alice requests it.</p>
  
  <p>If Alice doesn't upload a second image to the Gallery within N minutes, and Bob requests a new Gallery, then he'll get the first one.</p>
  
  <p>My question is what is a good JSON structure for this design &amp; what is an efficient way to construct the Mongo query?</p>
  
  <p>I'm open to alternative designs to give a user 1 Gallery that only has 1 Image in it at a time.</p>
  
  <p>ELABORATIONS:</p>
  
  <p>Gallery == battle.</p>
  
  <p>I'm building an "image battle" application. The end client will download a "battle" which has  1 or 2 images. In either case, the user picks 1 of the existing images, takes their own image then uploads.</p>
  
  <p>So I don't want Bob, Carly and David to all upload an image to Alice's Battle -- it's supposed to be just 2 images. Once Bob uploads an image to Alice's battle -- then Carly could download the battle, pick which one she likes, upload her own, then David (or anyone) could download it.. repeat.</p>