JavaScript MongoDB Limit fields and slice projection together mongodb limit fields returned,mongodb limit fields,mongodb find limit

I have the following User object:

{
  "_id" : ObjectId("someId"),
  "name" : "Bob",
  "password" : "fakePassword",
  "follower" : [...],
  "following" : [..]
}

I need to paginate over the follower list, so I use the slice projection operator, but I just need the paginated followers list to be returned. And I don't know if I am doing it the wrong way, or this can't be done, but limit fields doesn't work with slice projection.

Following are a couple of queries I tried:

 collection.findOne(
          {
            _id: new ObjectId(userId)
          },
          {
            follower: {$slice:[skip, parseInt(pageSize)]},
            follower: 1
          },..

and

collection.findOne(
          {
            _id: new ObjectId(userId)
          },
          {
            follower: 1,
            follower: {$slice:[skip, parseInt(pageSize)]}
          },

But these return all the values in the object, and does not limit the fields, although, the slice works fine in both the cases. Also when I do something like _id:0,following:0 , this part works, but I don't want to mention each and every field in the query like this, it may create problems once I decide to change the schema. How do I get this to work, what could be the syntax for the query to get this working..??

Answer:1

I am working through a project for a company I plan on working for and I was given a code challenge to create a choropleth map of Kenya. I have been able to generate the map using GeoJSON and TopoJSON ...

I am working through a project for a company I plan on working for and I was given a code challenge to create a choropleth map of Kenya. I have been able to generate the map using GeoJSON and TopoJSON ...

I am trying to show a list grouped by date but the list isn't sorted and I don't know when the date change. It's like I have this Json : list = {name: first, date: 2014-05-21}, { {name: second, date:...

I am trying to show a list grouped by date but the list isn't sorted and I don't know when the date change. It's like I have this Json : list = {name: first, date: 2014-05-21}, { {name: second, date:...

  1. array with arrays javascript
  2. array with arrays
  3. array with arrays python
  4. array with arrays php
  5. array with arrays c#
  6. array with arrays numpy
  7. array with arrays merge
  8. array with arrays in java
  9. array of arrays matlab
  10. array of arrays js
  11. array of arrays typescript
  12. array of arrays swift
  13. array of arrays vba
  14. array of arrays arduino
  15. array of arrays json
  16. array of arrays perl
  17. array of arrays bash
  18. array of arrays ruby
  19. array of arrays golang
  20. array of arrays powershell

How can i call a javascript function without any event. I have a session variable namely x. what I need is to call a javascript function demo() if the session variable is not null. <% if((String)...

How can i call a javascript function without any event. I have a session variable namely x. what I need is to call a javascript function demo() if the session variable is not null. <% if((String)...

  1. call function javascript in html
  2. call function javascript in php
  3. call function javascript when page load
  4. call function javascript by name
  5. call function javascript from another file
  6. call function javascript from c#
  7. call function javascript with parameters
  8. call function javascript button click
  9. call function javascript w3schools
  10. call function javascript onclick
  11. call function javascript in jquery
  12. call function javascript every 5 seconds
  13. call function javascript console
  14. call function javascript with arguments
  15. call function javascript after delay
  16. call function javascript dynamically
  17. call function javascript onclick button

I've got a load of very similar functions that do different things I'm trying to refactor this. Below I've created a generic_command: function generic_command(name, run){ var start_position = $('...

I've got a load of very similar functions that do different things I'm trying to refactor this. Below I've created a generic_command: function generic_command(name, run){ var start_position = $('...

  1. create generic function java
  2. create generic function c#
  3. create generic function swift
  4. create generic function typescript
  5. create generic function r
  6. create generic function vb.net
  7. kotlin create generic function
  8. jquery create generic function
  9. create generic datasource using function module
  10. how to create generic function in javascript