mongoc_gridfs_t *
_mongoc_gridfs_new (mongoc_client_t *client,
                    const char      *db,
                    const char      *prefix,
                    bson_error_t    *error)
{
   mongoc_gridfs_t *gridfs;
   const mongoc_read_prefs_t *read_prefs;
   const mongoc_read_concern_t *read_concern;
   const mongoc_write_concern_t *write_concern;
   char buf[128];
   bool r;
   uint32_t prefix_len;

   ENTRY;

   BSON_ASSERT (client);
   BSON_ASSERT (db);

   if (!prefix) {
      prefix = "fs";
   }

   /* make sure prefix is short enough to bucket the chunks and files
    * collections
    */
   prefix_len = (uint32_t)strlen (prefix);
   BSON_ASSERT (prefix_len + sizeof (".chunks") < sizeof (buf));

   gridfs = (mongoc_gridfs_t *) bson_malloc0 (sizeof *gridfs);

   gridfs->client = client;

   read_prefs = mongoc_client_get_read_prefs (client);
   read_concern = mongoc_client_get_read_concern (client);
   write_concern = mongoc_client_get_write_concern (client);

   bson_snprintf (buf, sizeof(buf), "%s.chunks", prefix);
   gridfs->chunks = _mongoc_collection_new (client, db, buf, read_prefs,
                                            read_concern, write_concern);

   bson_snprintf (buf, sizeof(buf), "%s.files", prefix);
   gridfs->files = _mongoc_collection_new (client, db, buf, read_prefs,
                                           read_concern, write_concern);

   r = _mongoc_gridfs_ensure_index (gridfs, error);

   if (!r) {
      mongoc_gridfs_destroy (gridfs);
      RETURN (NULL);
   }

   RETURN (gridfs);
}
Пример #2
0
Object HHVM_METHOD(MongoDBDriverManager, getReadPreference)
{
	MongoDBDriverManagerData *data = Native::data<MongoDBDriverManagerData>(this_);

	Class *c_rp = Unit::lookupClass(s_MongoDriverReadPreference_className.get());
	assert(c_rp);
	Object rp_obj = Object{c_rp};
	MongoDBDriverReadPreferenceData* rp_data = Native::data<HPHP::MongoDBDriverReadPreferenceData>(rp_obj.get());

	rp_data->m_read_preference = mongoc_read_prefs_copy(mongoc_client_get_read_prefs(data->m_client));

	return rp_obj;
}