Vous êtes sur la page 1sur 6

Blablab

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66

Presentation of the new equation


{F

Presentation of the new equation


{

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66

  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66

    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66

  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
la

Presentation of the new equation


{
  "documentList": [
    {
      "userId":

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
userId": 1234,
      "userName": "Adam Cook",
      

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
"age": 66

Presentation of the new equation


{
  "d

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
ocumentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66

adsf jkerijd
Asdfojerj
Dfjkask
Zxsafkdf
4454d sdfgsda
4dsaf1

45621321as

Presentation of the new equation


{
  "documentList": [
    {
      "userId": 1559,
      "userName": "David Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Adam Cook",
      "age": 66
    },
    {
      "userId": 1234,
      "userName": "Dale Sawyer",
      "age": 11
    },
    {
      "userId": 4230,
      "userName": "Adam Cook",
      "age": 44
    }
  ]
}

Disclaimer
This tool is rough, but it works. A list of possible improvements:

 Read the file asynchronously


 Stream the output instead of storing it in memory
 Use joi for input validation
 Add help to the command-line interface
 Add optional per-field uniqueness guarantees
 Allow for alternate template inputs such as a range of numbers instead of an
array

Why this document is important


import { Random } from 'meteor/random';

const getRandomDocuments = function(amount) {


// finds the next _id >= from a random one
const randomId = Random.id();
const gteRandom = MyCollection.find({
_id: { $gte: randomId }
}, {
fields: { _id: 1 },
sort: [
['_id', 'asc']
],
limit: amount
});
const remainingToGet = Math.max(0, amount - gteRandom.count());
// if it didn't find enough looks for next _id < the random one
const ltRandom = MyCollection.find({
_id: { $lt: randomId }
}, {
fields: { _id: 1 },
sort: [
['_id', 'asc']
],
limit: remainingToGet
});
// combine the two queries
let allIds = [];
gteRandom.forEach(function(doc) {
allIds.push(doc._id);
});
ltRandom.forEach(function(doc) {
allIds.push(doc._id);
});
return MyCollection.find({
_id: { $in: allIds }

Vous aimerez peut-être aussi