See http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_replace
169888
def find_one_and_replace(self, filter, replacement, **kwargs):
        
        self._arctic_lib.check_quota()
        return self._collection.find_one_and_replace(filter, replacement, **kwargs)
72208
async def update(self, _id=None, **new_data):
		
		if not _id or not new_data:
			return {"error":400, 
					"reason":"Missed required fields"}

		document = await self.collection.find_one({"id":_id})
		if not document:
			return {"error":404, 
					"reason":"Not found"}

		for key in new_data:
			await self.collection.find_one_and_update(
							{"id": _id},
							{"$set": {key: new_data[key]}}
						)
		updated = await self.collection.find_one({"id":_id})
		return {"success":200, "reason": "Updated", **updated}
797439
function attemptReplacePatterns(token, replacements, measureThreshold) {
  var replacement = null;

  for(var i = 0; i < replacements.length; i++) {
    if(!measureThreshold || measure(attemptReplace(token, replacements[i][0], '')) > measureThreshold)
      replacement = attemptReplace(token, replacements[i][0], replacements[i][1]);

    if(replacement)
      break;
  }

  return replacement;
}
694004
def update(self, **kwargs):
        
        if self.is_valid:
            if '_id' in self._document:
                to_update = self.find_one({'_id': self._id})

                if to_update:
                    before = self.before_update(old=to_update)
                    if before:
                        return before

                    try:
                        self.replace_one({'_id': self._id}, self._document)

                        self.after_update(old=to_update)

                        return self._document
                    except PyMongoException as exc:
                        return PyMongoError(
                            error_message=exc.details.get(
                                'errmsg', exc.details.get(
                                    'err', 'PyMongoError.'
                                )
                            ),
                            operation='update', collection=type(self).__name__,
                            document=self._document,
                        )
                else:
                    return DocumentNotFoundError(type(self).__name__, self._id)
            else:
                return UnidentifiedDocumentError(
                    type(self).__name__, self._document
                )

        return self._errors
368181
function(replace, count, callback) {
    return pathmap.replace(
      pathmap.chomp(this, pathmap.extname(this)), replace, callback);
  }
57649
function(str, obj) {
    var replacer = function(wholeMatch, key) {
      return obj[key] === undefined ? wholeMatch : obj[key];
    },
    regexp = new RegExp('{{\\s*([a-z0-9-_]+)\\s*}}',"ig");

    for(var beforeReplace = ""; beforeReplace !== str; str = (beforeReplace = str).replace(regexp, replacer)){

    }
    return str;
  }
596014
def _update(collection_name, upsert, multi, spec, doc, check_keys, opts):
    """"""
    flags = 0
    if upsert:
        flags += 1
    if multi:
        flags += 2
    encode = _dict_to_bson  # Make local. Uses extensions.
    encoded_update = encode(doc, check_keys, opts)
    return b"".join([
        _ZERO_32,
        _make_c_string(collection_name),
        _pack_int(flags),
        encode(spec, False, opts),
        encoded_update]), len(encoded_update)
1058947
def get_one(cls, db, *args, **kwargs):
        
        data = db[cls.collection].find_one(*args, **kwargs)
        if data:
            return cls.wrap_incoming(data, db)
        else:
            return None
782871
def one(cls, path='', index=0):
        """"""
        url = urljoin(cls._meta.base_url, path)
        pq_items = cls._get_items(url=url, **cls._meta._pyquery_kwargs)
        item = pq_items.eq(index)
        if not item:
            raise ItemDoesNotExist("%s not found" % cls.__name__)
        return cls(item=item)
1256708
def find_one(self, query=None):
        
        try:
            return self.find(query=query, limit=1)[0]
        except (sqlite3.OperationalError, IndexError):
            return None
620781
def get_one(self, schema, query=None, **kwargs):
        
        ret = self._get_query(self._get_one, schema, query, **kwargs)
        if not ret: ret = {}
        return ret
126774
public boolean replaceWith(Collection collection) {
        boolean changed = false;
        if (items.size() > 0) {
            items.clear();
            changed = true;
        }
        if (items.addAll(0, collection) && !changed) {
            changed = true;
        }
        if (changed) {
            fireContentsChanged(-1, -1);
        }
        return changed;
    }
1276878
def find_by_id(self, _id, **kwargs):
        

        if type(_id) == dict and _id.get("_id"):
            return self.find_one({"_id": ObjectId(_id["_id"])}, **kwargs)

        return self.find_one({"_id": ObjectId(_id)}, **kwargs)
548153
def multiple_replace(string, replacements):
    # type: (str, Dict[str,str]) -> str
    
    pattern = re.compile("|".join([re.escape(k) for k in sorted(replacements, key=len, reverse=True)]), flags=re.DOTALL)
    return pattern.sub(lambda x: replacements[x.group(0)], string)
984030
function _replaceRegex (cartoError, listedError) {
  if (!listedError.friendlyMessage) {
    return cartoError.message;
  }
  var match = cartoError.message && cartoError.message.match(listedError.messageRegex);
  if (match && match.length > 1) {
    var replaced = listedError.friendlyMessage.replace('$0', match[1]);
    if (match.length > 2) {
      replaced = replaced.replace('$1', match[2]);
    }
    return replaced;
  }
  return listedError.friendlyMessage;
}
126793
def find_one(cls, *args, **kwargs):
        """"""
        d = cls.collection.find_one(*args, **kwargs)
        if d:
            return cls(**d)
1366608
def _find_and_replace(self, date_string, captures):
        
        # add timezones to replace
        cloned_replacements = copy.copy(REPLACEMENTS)  # don't mutate
        for tz_string in captures.get("timezones", []):
            cloned_replacements.update({tz_string: " "})

        date_string = date_string.lower()
        for key, replacement in cloned_replacements.items():
            # we really want to match all permutations of the key surrounded by whitespace chars except one
            # for example: consider the key = 'to'
            # 1. match 'to '
            # 2. match ' to'
            # 3. match ' to '
            # but never match r'(\s|)to(\s|)' which would make 'october' > 'ocber'
            date_string = re.sub(
                r"(^|\s)" + key + r"(\s|$)",
                replacement,
                date_string,
                flags=re.IGNORECASE,
            )

        return date_string, self._pop_tz_string(sorted(captures.get("timezones", [])))