How do I validate a field of document in mongodb collection to array with mongocxx?

31 views Asked by At

I create a collection in mongodb with validator, but I can't insert document, it failed with Document failed validation: generic server error

    db.create_collection("testValidator1",
        make_document(
            kvp("validator", 
                make_document
                (kvp("arr", make_document(kvp("bsonType", "array")))
            ))
        ));
    auto temp = db["testValidator1"];
    temp.insert_one(make_document(
        kvp("arr", make_array(321, 322, 323))
    ));

I want to konw what is the correct format.

0

There are 0 answers