bool
mongoc_database_remove_all_users (mongoc_database_t *database,
                                  bson_error_t      *error)
{
   mongoc_collection_t *col;
   bson_error_t lerror;
   bson_t cmd;
   bool ret;

   ENTRY;

   bson_return_val_if_fail (database, false);

   bson_init (&cmd);
   BSON_APPEND_INT32 (&cmd, "dropAllUsersFromDatabase", 1);
   ret = mongoc_database_command_simple (database, &cmd, NULL, NULL, &lerror);
   bson_destroy (&cmd);

   if (!ret && (lerror.code == MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND)) {
      bson_init (&cmd);

      col = mongoc_client_get_collection (database->client, database->name,
                                          "system.users");
      BSON_ASSERT (col);

      ret = mongoc_collection_delete (col, MONGOC_DELETE_NONE, &cmd, NULL,
                                      error);

      bson_destroy (&cmd);
      mongoc_collection_destroy (col);
   }

   RETURN (ret);
}
static void
test_delete (void)
{
   mongoc_collection_t *collection;
   mongoc_database_t *database;
   mongoc_client_t *client;
   bson_context_t *context;
   bson_error_t error;
   bool r;
   bson_oid_t oid;
   bson_t b;
   int i;

   client = mongoc_client_new(gTestUri);
   ASSERT (client);

   database = get_test_database (client);
   ASSERT (database);

   collection = get_test_collection (client, "test_delete");
   ASSERT (collection);

   context = bson_context_new(BSON_CONTEXT_NONE);
   ASSERT (context);

   for (i = 0; i < 100; i++) {
      bson_init(&b);
      bson_oid_init(&oid, context);
      bson_append_oid(&b, "_id", 3, &oid);
      bson_append_utf8(&b, "hello", 5, "world", 5);
      r = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, &b, NULL,
                                   &error);
      if (!r) {
         MONGOC_WARNING("%s\n", error.message);
      }
      ASSERT (r);
      bson_destroy(&b);

      bson_init(&b);
      bson_append_oid(&b, "_id", 3, &oid);
      r = mongoc_collection_delete(collection, MONGOC_DELETE_NONE, &b, NULL,
                                   &error);
      if (!r) {
         MONGOC_WARNING("%s\n", error.message);
      }
      ASSERT (r);
      bson_destroy(&b);
   }

   r = mongoc_collection_drop (collection, &error);
   ASSERT (r);

   mongoc_collection_destroy(collection);
   mongoc_database_destroy(database);
   bson_context_destroy(context);
   mongoc_client_destroy(client);
}
Example #3
0
static int mongo_del_secret(u08bits *secret, u08bits *realm) {
  mongoc_collection_t * collection = mongo_get_collection("turn_secret"); 

	if(!collection)
    return -1;
    
  bson_t query;
  bson_init(&query);
  BSON_APPEND_UTF8(&query, "realm", (const char *)realm);
	if(secret && (secret[0]!=0)) {
    BSON_APPEND_UTF8(&query, "value", (const char *)secret);
  }

  mongoc_collection_delete(collection, MONGOC_DELETE_NONE, &query, NULL, NULL);
  mongoc_collection_destroy(collection);
  bson_destroy(&query);
  return 0;
}
    static Variant HHVM_METHOD(MongoCollection, remove, Array criteria, Array options) {
        mongoc_collection_t *collection;
        bson_t criteria_b;
        bson_error_t error;

        collection = get_collection(this_);

        encodeToBSON(criteria, &criteria_b);
        mongoc_delete_flags_t delete_flag = MONGOC_DELETE_NONE;
        int w_flag = MONGOC_WRITE_CONCERN_W_DEFAULT;
        //如果传递了参数
        if(!options.empty()){
            //printf("multiple = %s\r\n",options[String("multiple")].toBoolean() ? "true":"false");
            if(options[String("justOne")].toBoolean()==true){
                delete_flag = MONGOC_DELETE_SINGLE_REMOVE;
            }
            
        }
        mongoc_write_concern_t *write_concern;
        write_concern = mongoc_write_concern_new();
        mongoc_write_concern_set_w(write_concern, w_flag);
        bool ret = mongoc_collection_delete(collection, delete_flag, &criteria_b, write_concern, &error);

        if (!ret) {
            mongoThrow<MongoCursorException>((const char *) error.message);
        }
        mongoc_collection_destroy(collection);
        bson_destroy(&criteria_b);
        
        
        
        return ret;
        /*
        bool mongoc_collection_delete (mongoc_collection_t           *collection,
                                      mongoc_delete_flags_t          flags,
                                      const bson_t                  *selector,
                                      const mongoc_write_concern_t  *write_concern,
                                      bson_error_t                  *error);
         */
    }
Example #5
0
static int mongo_del_oauth_key(const u08bits *kid) {

  mongoc_collection_t * collection = mongo_get_collection("oauth_key");

  if(!collection)
    return -1;

  bson_t query;
  bson_init(&query);
  BSON_APPEND_UTF8(&query, "kid", (const char *)kid);

  int ret = -1;

  if (!mongoc_collection_delete(collection, MONGOC_DELETE_SINGLE_REMOVE, &query, NULL, NULL)) {
    TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error deleting oauth key information\n");
  } else {
    ret = 0;
  }
  mongoc_collection_destroy(collection);
  bson_destroy(&query);
  return ret;
}
Example #6
0
static int mongo_del_user(u08bits *usname, u08bits *realm) {
  mongoc_collection_t * collection = mongo_get_collection("turnusers_lt");

	if(!collection)
    return -1;
    
  bson_t query;
  bson_init(&query);
  BSON_APPEND_UTF8(&query, "name", (const char *)usname);
  BSON_APPEND_UTF8(&query, "realm", (const char *)realm);
  
  int ret = -1;    

  if (!mongoc_collection_delete(collection, MONGOC_DELETE_SINGLE_REMOVE, &query, NULL, NULL)) {
    TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error deleting user key information\n");
  } else {
    ret = 0;
  }
  mongoc_collection_destroy(collection);
  bson_destroy(&query);
  return ret;
}